package com.msb.mall.producet.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.msb.common.valid.groups.AddGroupsInterface;
import com.msb.common.valid.groups.UpdateGroupsInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.msb.mall.producet.entity.BrandEntity;
import com.msb.mall.producet.service.BrandService;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;


/**
 * 品牌
 *
 * @author zhangjiajun
 * @email 1606516025@qq.com
 * @date 2025-05-08 21:19:06
 */
@RefreshScope
@RestController
@RequestMapping("/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;


    @Value("${user.username}")
    private String name;

    @GetMapping("/all")
    public R queryAllBrand(){
        BrandEntity brandEntity = new BrandEntity();
        brandEntity.setName("华为");
        return R.ok().put("brand", brandEntity);
    }

    @GetMapping("/name")
    public R name(){

        return R.ok().put("name", name);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Validated(AddGroupsInterface.class) @RequestBody BrandEntity brand){

		brandService.save(brand);

        return R.ok();
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@Validated(UpdateGroupsInterface.class) @RequestBody BrandEntity brand){
//		brandService.updateById(brand);
        brandService.updateDetail(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
